﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MS.InformationManagement.Support;
using Microsoft.SharePoint;
using System.DirectoryServices.AccountManagement;
using MS.InformationManagement.Presenter.ValidarPassword;
using MS.InformationManagement.Support.Constants;
using MS.InformationManagement.Presenter.Support;

namespace MS.InformationManagement.Controls._CONTROLTEMPLATES.InformationManagerControls
{
    public partial class ValidarPassword : BaseControl, IValidarPasswordView
    {

        #region fields

        ValidarPasswordPresenter _presenter;

        #endregion

        #region Properties

        public Guid GuidCurrentList
        {
            get { return new Guid(Page.Request.QueryString["lstID"]); }
        }
        public string PassWord { get; set; }
        public bool result { get; set; }
        public string Domain{ get; set; }
        public string UserName { get; set; }
        public int CurrentId
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["ID"]))
                    return 0;
                else
                    return int.Parse(Page.Request.QueryString["ID"]);
            }
        }
        public string form
        {
            get { return Page.Request.QueryString["form"]; }
        }

        #endregion

        #region Form Methods

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (form == "Prestamo")
                lblInfo.Text = "Para aceptar el prestamo, por favor ingrese su contraseña del sistema. Gracias";

            if (form == "Devolucion")
                lblInfo.Text = "Para aceptar la devolución , por favor ingrese su contraseña del sistema. Gracias";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter = new ValidarPasswordPresenter(this);
            _presenter.CargarValores();
            
        }

        protected void CloseAction(object sender, EventArgs e)
        {
            this.CloseWindow();
        }

        protected void SaveAction(object sender, EventArgs e)
        {
            try
            {
                PassWord = txtPassword.Text;
                _presenter.VerificarUsuario();
            }
            catch (Exception ex)
            {
                HandleWarning(ex.Message);
            }
        }

        #endregion

        #region Implemented Methods

        public void ShowResult()
        {
            if (result == true)
            {
                this._ShowAlertAndClose("Su solicitud ha sido registrada");
            }
            else
            {
                this._ShowAlertAndClose("Ha ocurrido un error al ingresar su solicitud");
            }
        }

        public void Show()
        {
            txtDominio.Text = Domain;
            txtCurrentUser.Text = UserName;
        }

        #endregion
    }
}
